package com.drinks.yiniang.adapter.user.order;

import android.content.Context;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.user.order.OrderConfirmJson;
import com.drinks.yiniang.ui.widget.layout.ShoppingCartCounterLayout;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 确认订单商品列表adapter
 * @author han
 * @date 2019/8/30
 */
public class OrdeConfirmAdapter extends BaseQuickRCVAdapter<OrderConfirmJson.OrderConfirmGoods, BaseViewHolder> {
    
    private StringBuilder mBuilder;

    public OrdeConfirmAdapter(Context mContext, @Nullable List<OrderConfirmJson.OrderConfirmGoods> data) {
        super(R.layout.item_order_confirm_goods, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderConfirmJson.OrderConfirmGoods item) {
        GlideUtils.loadSquareImage(mContext, (RatioRoundImageView) helper.getView(R.id.iv_order_confirm_goods_cover), item.getCover_url());
        //名称
        helper.setText(R.id.tv_order_confirm_goods_name, item.getName());
        //价格
        mBuilder = new StringBuilder("¥");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getApp_price()));
        helper.setText(R.id.tv_order_confirm_goods_price, mBuilder);
        //推荐语
        helper.setText(R.id.tv_order_confirm_goods_slogan, item.getRecommend_reason());
        //属性
        mBuilder = new StringBuilder();
        mBuilder.append(StringUtils.judgeGreaterNumber(item.getSingle_capacity(), 0f) ? item.getSingle_capacity() : "");
        mBuilder.append(mBuilder.length() > 0 ? "ml" : "");
        helper.setText(R.id.tv_order_confirm_goods_volume, mBuilder);
        //数量
        //ShoppingCartCounterLayout counterLayout = helper.getView(R.id.ll_order_confirm_counter);
        //counterLayout.setTextCount(item.getNum());
        helper.setText(R.id.tv_order_confirm_counter, "x" + StringUtils.getNullEmptyConvert__(item.getNum()));
    }
}
